[id].vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. <template>
  2. <div id="newsList">
  3. <!-- 页面头部 -->
  4. <HomePageHead></HomePageHead>
  5. <!-- Banner1 -->
  6. <HomeBanner1></HomeBanner1>
  7. <!-- 面包屑导航 -->
  8. <div class="breadcrumb">
  9. <div class="inner">
  10. <span class="location">当前位置:</span>
  11. <el-breadcrumb :separator-icon="ArrowRight">
  12. <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
  13. <el-breadcrumb-item :to="{ path: '/newsList' }">{{ name }}</el-breadcrumb-item>
  14. </el-breadcrumb>
  15. </div>
  16. </div>
  17. <!-- 资讯列表 -->
  18. <div class="newsList">
  19. <div class="inner">
  20. <div class="innerLeft">
  21. <ul class="list">
  22. <li v-for="(item, index) in newsList" :key="index">
  23. <!-- <NuxtLink to="/primaryNavigation/newsDetail/newsDetail">{{ item }}</NuxtLink> -->
  24. <!-- <NuxtLink to="/newsDetail/newsDetail">{{ item.title }}</NuxtLink> -->
  25. <NuxtLink :to="{ path: `/newsDetail/${item.id}`, query: { listId: routeId, listName: routeName } }"
  26. target="_blank">{{ item.title }}</NuxtLink>
  27. </li>
  28. </ul>
  29. <!-- 分页器 -->
  30. <div class="pagination">
  31. <el-pagination size="small" background layout="prev, pager, next" :total="total" class="mt-4"
  32. prev-text="上一页" next-text="下一页" @change="changePage" />
  33. <!-- <HomePagination @sendData="handleData"></HomePagination> -->
  34. </div>
  35. </div>
  36. <div class="innerRight">
  37. <DetailHotNews></DetailHotNews>
  38. </div>
  39. </div>
  40. </div>
  41. <!-- 三农资讯logo -->
  42. <HomeSannongzixun></HomeSannongzixun>
  43. <!-- 资讯推荐 -->
  44. <div class="zixuntuijian">
  45. <div class="inner">
  46. <div class="innerLeft">
  47. <div class="zixunLeft">
  48. <!-- 标题部分 -->
  49. <div class="title">
  50. <h3>
  51. 资讯推荐
  52. <!-- <span>查看更多</span> -->
  53. </h3>
  54. </div>
  55. <!-- 图片和文字列表 -->
  56. <ul class="photo_text">
  57. <li v-for="item in news1">
  58. <img :src="item.imgurl" alt="">
  59. <div>
  60. <h5>{{ item.title }}</h5>
  61. <p>
  62. <span>{{ item.author }}</span>
  63. <span>{{ item.created_at }}</span>
  64. </p>
  65. </div>
  66. </li>
  67. <li v-for="item in news11">
  68. <em></em>
  69. {{ item.title }}
  70. </li>
  71. </ul>
  72. </div>
  73. <div class="zixunRight">
  74. <!-- 标题部分 -->
  75. <div class="title">
  76. <h3>
  77. 资讯推荐
  78. <!-- <span>查看更多</span> -->
  79. </h3>
  80. </div>
  81. <!-- 图片和文字列表 -->
  82. <ul class="photo_text">
  83. <li v-for="item in news2">
  84. <img :src="item.imgurl" alt="">
  85. <div>
  86. <h5>{{ item.title }}</h5>
  87. <p>
  88. <span>{{ item.author }}</span>
  89. <span>{{ item.created_at }}</span>
  90. </p>
  91. </div>
  92. </li>
  93. <li v-for="item in news22">
  94. <em></em>
  95. {{ item.title }}
  96. </li>
  97. </ul>
  98. </div>
  99. </div>
  100. <div class="innerRight">
  101. <!-- 标题部分 -->
  102. <div class="title">
  103. <h4>
  104. 热点资讯
  105. <!-- <span>查看更多</span> -->
  106. </h4>
  107. </div>
  108. <!-- 列表 -->
  109. <ul class="rightList">
  110. <li v-for="item in hotlistall">
  111. <img class="left" :src="item.imgurl">
  112. <p class="left">{{ item.title }}</p>
  113. </li>
  114. </ul>
  115. </div>
  116. </div>
  117. </div>
  118. <!-- 页面底部 -->
  119. <HomeFoot></HomeFoot>
  120. </div>
  121. </template>
  122. <script setup>
  123. import { onMounted } from 'vue';
  124. import { ElBreadcrumb, ElBreadcrumbItem, ElPagination } from 'element-plus'
  125. import { ArrowRight } from '@element-plus/icons-vue'
  126. const nuxtApp = useNuxtApp();
  127. const axios = nuxtApp.$axios;
  128. //获得跳转过来的id
  129. const route = useRoute();
  130. const articleId = route.params.id; //获得该页面的id
  131. const category_id = route.query.category_id; //获得该页面的id
  132. const name = route.query.name; //获得该页面的id
  133. console.log(name);
  134. //关键词
  135. let keyWord = useState("keyWord", () => "")
  136. let id = useState("id", () => "")
  137. let total = useState("total", () => 0)
  138. let page = useState("page", () => 1)
  139. let pageSize = useState("pageSize", () => 10)
  140. onMounted(() => {
  141. id.value = route.query.id;
  142. console.log('id', id.value);
  143. })
  144. // 页码
  145. // //页面组件传递数据的时间驱动函数
  146. // const handleData = (data) => {
  147. // console.log(data.value)
  148. // page.value = data.value
  149. // //在页码发生变化时去请求响应页面的新闻数据
  150. // axios.get(`/web/getWebsiteArticleList?page=${page.value}&pageSize=${10}&catid=${14}&keyword=${keyWord.value}`).then(response => {
  151. // // console.log(response.data.rows);
  152. // newsList.value = response.data.rows;
  153. // }).catch(error => {
  154. // console.error(error);
  155. // })
  156. // }
  157. let changePage = (value) => {
  158. console.log("当前页码", value);
  159. page.value = value
  160. console.log(page.value);
  161. newslists()
  162. }
  163. // 新闻列表
  164. const newsList = useState("newsList", () => '');
  165. const newslists = async () => {
  166. try {
  167. const response = await axios.get(`/web/getWebsiteArticleList?page=${page.value}&pageSize=${pageSize.value}&catid=${category_id}`);
  168. // console.log(response.data.rows);
  169. newsList.value = response.data.rows;
  170. total.value = response.data.count;
  171. } catch (error) {
  172. console.error(error);
  173. }
  174. }
  175. //热点资讯
  176. const hotlistall = useState("hotlistall", () => "");
  177. const hotlist = async () => {
  178. try {
  179. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${2}&level=${4}&placeid=${1}`);
  180. console.log('热点资讯', response.data);
  181. for (let item of response.data) {
  182. console.log(item);
  183. item.count = 1;
  184. }
  185. hotlistall.value = response.data;
  186. } catch (error) {
  187. console.error(error);
  188. }
  189. }
  190. //资讯推荐1
  191. const news1 = useState("news1", () => "");
  192. const newslist1 = async () => {
  193. try {
  194. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${1}&level=${5}&placeid=${1}`);
  195. console.log('热点资讯', response.data);
  196. news1.value = response.data;
  197. } catch (error) {
  198. console.error(error);
  199. }
  200. }
  201. const news11 = useState("news11", () => "");
  202. const newslist11 = async () => {
  203. try {
  204. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${3}&level=${5}&placeid=${1}`);
  205. console.log('热点资讯', response.data);
  206. news11.value = response.data;
  207. } catch (error) {
  208. console.error(error);
  209. }
  210. }
  211. //资讯推荐2
  212. const news2 = useState("news2", () => "");
  213. const newslist2 = async () => {
  214. try {
  215. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${1}&level=${5}&placeid=${1}`);
  216. console.log('热点资讯', response.data);
  217. news2.value = response.data;
  218. } catch (error) {
  219. console.error(error);
  220. }
  221. }
  222. const news22 = useState("news22", () => "");
  223. const newslist22 = async () => {
  224. try {
  225. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${3}&level=${5}&placeid=${1}`);
  226. console.log('热点资讯', response.data);
  227. news22.value = response.data;
  228. } catch (error) {
  229. console.error(error);
  230. }
  231. }
  232. //挂载成功钩子函数
  233. onMounted(() => {
  234. // 资讯推荐
  235. newslists()
  236. // 热点资讯
  237. hotlist()
  238. // 资讯推荐
  239. newslist1()
  240. newslist2()
  241. // 热点资讯
  242. newslist11()
  243. newslist22()
  244. })
  245. //路由中间件
  246. definePageMeta({
  247. middleware: 'auth'
  248. })
  249. </script>
  250. <style lang="less" scoped>
  251. //导航条
  252. .breadcrumb {
  253. width: 100%;
  254. height: 22px;
  255. margin-bottom: 30px;
  256. font-family: Microsoft YaHei, Microsoft YaHei;
  257. font-weight: 400;
  258. font-size: 20px;
  259. color: #666666;
  260. line-height: 23px;
  261. text-align: left;
  262. font-style: normal;
  263. text-transform: none;
  264. :deep(.el-breadcrumb) {
  265. display: inline-block;
  266. vertical-align: -4px;
  267. }
  268. :deep(.el-breadcrumb__inner a),
  269. :deep(.el-breadcrumb__inner.is-link) {
  270. color: #666666;
  271. font-weight: 400;
  272. text-decoration: none;
  273. transition: var(--el-transition-color);
  274. }
  275. span {
  276. font-family: Microsoft YaHei, Microsoft YaHei;
  277. font-weight: 400;
  278. font-size: 20px;
  279. color: #666666;
  280. line-height: 23px;
  281. text-align: left;
  282. font-style: normal;
  283. text-transform: none;
  284. }
  285. span:hover {
  286. color: #666666;
  287. }
  288. .location {
  289. margin-right: 20px;
  290. width: 100px;
  291. height: 22px;
  292. font-family: Microsoft YaHei, Microsoft YaHei;
  293. font-weight: 400;
  294. font-size: 20px;
  295. color: #666666;
  296. line-height: 23px;
  297. text-align: left;
  298. font-style: normal;
  299. text-transform: none;
  300. }
  301. }
  302. // 资讯列表
  303. .newsList {
  304. width: 100%;
  305. height: 675px;
  306. margin-bottom: 70px;
  307. .inner {
  308. width: 1200px;
  309. .innerLeft,
  310. .innerRight {
  311. border-top: 1px solid #139602;
  312. }
  313. .innerLeft {
  314. height: 675px;
  315. >.list {
  316. height: 570px;
  317. margin-bottom: 70px;
  318. >li {
  319. width: 790px;
  320. height: 56px;
  321. white-space: nowrap;
  322. overflow: hidden;
  323. text-overflow: ellipsis;
  324. line-height: 56px;
  325. border-bottom: 1px solid #D9D9D9;
  326. >a {
  327. width: 360px;
  328. height: 26px;
  329. font-family: Microsoft YaHei, Microsoft YaHei;
  330. font-weight: 400;
  331. font-size: 20px;
  332. color: #333333;
  333. line-height: 26px;
  334. text-align: left;
  335. font-style: normal;
  336. text-transform: none;
  337. }
  338. }
  339. >li:hover>a {
  340. color: #139602;
  341. }
  342. >li:nth-child(1)::after,
  343. >li:nth-child(2)::after {
  344. content: "热";
  345. margin-left: 13px;
  346. background: #FF8A37;
  347. color: #fff;
  348. font-size: 14px;
  349. padding: 0px 2px;
  350. }
  351. }
  352. >.pagination {
  353. width: 800px;
  354. height: 34px;
  355. margin-left: 141px;
  356. display: flex;
  357. justify-content: center;
  358. margin: 0;
  359. // 鼠标移入后字体颜色
  360. .el-pagination::v-deep :hover {
  361. color: #139609;
  362. }
  363. .el-pagination.is-background::v-deep .btn-next,
  364. .el-pagination.is-background::v-deep .btn-prev {
  365. width: 70px;
  366. height: 34px;
  367. margin: 0px 10px;
  368. border-radius: 4px;
  369. }
  370. .el-pagination.is-background::v-deep .el-pager li {
  371. margin: 0px 10px;
  372. width: 38px;
  373. height: 34px;
  374. border-radius: 4px;
  375. }
  376. .el-pagination.is-background::v-deep .btn-next.is-active,
  377. .el-pagination.is-background::v-deep .btn-prev.is-active,
  378. .el-pagination.is-background::v-deep .el-pager li.is-active {
  379. background-color: #028e21;
  380. color: #fff;
  381. }
  382. }
  383. }
  384. .innerRight {
  385. width: 381px;
  386. height: 605px;
  387. }
  388. }
  389. }
  390. //资讯推荐
  391. .zixuntuijian {
  392. width: 100%;
  393. height: 290px;
  394. margin-bottom: 70px;
  395. .innerLeft {
  396. // 左侧
  397. .zixunLeft {
  398. margin-right: 30px;
  399. }
  400. .zixunRight,
  401. .zixunLeft {
  402. float: left;
  403. width: 380px;
  404. height: 290px;
  405. // 标题部分
  406. >.title {
  407. width: 380px;
  408. }
  409. >.title>h3 {
  410. height: 36px;
  411. font-family: Source Han Sans, Source Han Sans;
  412. font-weight: bold;
  413. font-size: 24px;
  414. color: #000000;
  415. line-height: 28px;
  416. text-align: left;
  417. font-style: normal;
  418. text-transform: none;
  419. border-bottom: 1px solid #139602;
  420. }
  421. >.title>h3>span {
  422. float: right;
  423. width: 56px;
  424. height: 20px;
  425. line-height: 24px;
  426. font-weight: 400;
  427. font-size: 14px;
  428. color: #999999;
  429. font-style: normal;
  430. text-transform: none;
  431. }
  432. .photo_text {
  433. >li:first-child {
  434. width: 380px;
  435. height: 120px;
  436. margin-top: 20px;
  437. margin-bottom: 15px;
  438. position: relative;
  439. >img {
  440. float: left;
  441. width: 160px;
  442. height: 120px;
  443. }
  444. >div {
  445. float: left;
  446. width: 220px;
  447. height: 120px;
  448. padding-left: 15px;
  449. padding-top: 6px;
  450. box-sizing: border-box;
  451. background-color: #f6f6f6;
  452. >h5 {
  453. width: 200px;
  454. height: 54px;
  455. display: -webkit-box;
  456. -webkit-box-orient: vertical;
  457. -webkit-line-clamp: 2;
  458. overflow: hidden;
  459. text-overflow: ellipsis;
  460. word-break: break-all;
  461. font-family: Source Han Sans, Source Han Sans;
  462. font-weight: 500;
  463. font-size: 18px;
  464. color: #333333;
  465. line-height: 26px;
  466. text-align: left;
  467. font-style: normal;
  468. text-transform: none;
  469. }
  470. >p {
  471. width: 200px;
  472. height: 22px;
  473. line-height: 20px;
  474. position: absolute;
  475. bottom: 5px;
  476. right: 0;
  477. >span {
  478. display: inline-block;
  479. // width: 100px;
  480. height: 18px;
  481. font-family: Source Han Sans, Source Han Sans;
  482. font-weight: 400;
  483. font-size: 12px;
  484. color: #999999;
  485. text-align: left;
  486. line-height: 14px;
  487. font-style: normal;
  488. text-transform: none;
  489. }
  490. >span:last-child {
  491. // width: 90px;
  492. text-align: right;
  493. margin-left: 20px;
  494. }
  495. }
  496. }
  497. }
  498. >li {
  499. width: 380px;
  500. height: 25px;
  501. white-space: nowrap;
  502. overflow: hidden;
  503. text-overflow: ellipsis;
  504. font-family: PingFang SC, PingFang SC;
  505. font-weight: 500;
  506. font-size: 18px;
  507. color: #333333;
  508. line-height: 21px;
  509. text-align: left;
  510. font-style: normal;
  511. text-transform: none;
  512. margin-bottom: 10px;
  513. em {
  514. display: inline-block;
  515. width: 8px;
  516. height: 8px;
  517. border-radius: 8px;
  518. margin-right: 10px;
  519. background-color: #d9d9d9;
  520. }
  521. }
  522. >li:hover {
  523. color: #139602;
  524. }
  525. >li:hover em {
  526. background-color: #139602;
  527. }
  528. }
  529. }
  530. }
  531. .innerRight {
  532. width: 381px;
  533. height: 290px;
  534. background-color: #fbfbfb;
  535. >.title {
  536. width: 380px;
  537. height: 40px;
  538. line-height: 40px;
  539. border-top: 1px solid #139602;
  540. border-bottom: 1px solid #e7e7e7;
  541. >h4 {
  542. font-family: Microsoft YaHei, Microsoft YaHei;
  543. font-weight: 400;
  544. margin-left: 20px;
  545. font-size: 20px;
  546. color: #000000;
  547. text-align: left;
  548. font-style: normal;
  549. text-transform: none;
  550. >span {
  551. float: right;
  552. font-family: Microsoft YaHei, Microsoft YaHei;
  553. font-weight: 400;
  554. font-size: 14px;
  555. margin-right: 10px;
  556. color: #999999;
  557. text-align: left;
  558. font-style: normal;
  559. text-transform: none;
  560. }
  561. }
  562. }
  563. .rightList {
  564. height: 540px;
  565. margin-top: 20px;
  566. >li {
  567. height: 100px;
  568. margin-bottom: 10px;
  569. >img {
  570. width: 150px;
  571. height: 100px;
  572. }
  573. >p {
  574. width: 219px;
  575. height: 100px;
  576. padding-left: 12px;
  577. font-family: PingFang SC, PingFang SC;
  578. font-weight: 400;
  579. font-size: 16px;
  580. color: #333333;
  581. line-height: 22px;
  582. text-align: left;
  583. font-style: normal;
  584. text-transform: none;
  585. }
  586. >p:hover {
  587. box-shadow: 0 0 16px 1px rgba(0, 0, 0, 0.1);
  588. }
  589. }
  590. }
  591. }
  592. }
  593. </style>